import React, { useEffect,useState } from 'react'
import Top from '../../components/Top/Top'
import { reqNew, reqGroupon, reqSeckill, reqIndexgoods, reqCate, reqCoupon, reqCartadd } from "../../request/api"
import List from './components/List/List'
import Goods from './components/Goods/Goods'
import Groupons from './components/Groupons/Groupons'
import Seckill from './components/Seckill/Seckill'
import IndexGoods from "./components/IndexGoods/IndexGoods"
import Coupon from "./components/Coupon/Coupon"
import "./home.css"
const Home = () => {
    const title = "商品首页"
    //定变量-初始值
    const [NewsArr, setNewsArr] = useState([])
    const [groupons, setgroupons] = useState([])
    const [cateList, setcateList] = useState([])
    const [seckill, setseckill] = useState([])
    const [goods, setgoods] = useState([])
    const [n,setN]=useState(0)
    const [coupon, setcoupon] = useState([])
    const [c,setC]=useState(0)
    //进页面--发请求--修改
    useEffect(() => {
       
        reqNew().then(res => {
            if (res.data.code == 200) {
                setNewsArr(res.data.list)
            }
        })
        reqGroupon().then(res => {
            if (res.data.code == 200) {
                setgroupons(res.data.list)
            }
        })
        reqSeckill().then(res => {
            if (res.data.code == 200) {
                setseckill(res.data.list)
            }
        })
        reqIndexgoods().then(res => {
            if (res.data.code == 200) {
                //goods
                setgoods(res.data.list)
                //修改showgoods
            }
        })
        reqCate().then(res => {
            if (res.data.code == 200) {
                setcateList(res.data.list)
            }
        })
        reqCoupon().then(res => {
            if (res.data.code == 200) {
                setcoupon(res.data.list)
            }
        })
    }, [])



    console.log("============================");
    let showgoods=goods.length>0?goods[n].content:[];
    let showcoupon=coupon.length>0?coupon[c].content:[];
    let {uid}=JSON.parse(sessionStorage.getItem("info"))
    return (
        <div>
            <Top title={title}></Top>
            <List cateList={cateList}></List>
            <Goods news={NewsArr} reqCartadd={reqCartadd}></Goods>
            <Groupons groupons={groupons}></Groupons>
            <Seckill seckill={seckill}></Seckill>
            <Coupon showcoupon={showcoupon} setC={setC}></Coupon>
            <IndexGoods showgoods={showgoods} setN={setN}></IndexGoods>
            <div className="home_b_div"></div>
        </div>
    )
}

export default Home
